home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cinidemo / ftestini.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-05-10  |  11.0 KB  |  363 lines

  1. VERSION 5.00
  2. Begin VB.Form fTestIni 
  3.    Caption         =   "cINIFile Class Demonstration Application"
  4.    ClientHeight    =   5670
  5.    ClientLeft      =   3645
  6.    ClientTop       =   2310
  7.    ClientWidth     =   7200
  8.    BeginProperty Font 
  9.       Name            =   "Tahoma"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   400
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    Icon            =   "fTestIni.frx":0000
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   5670
  20.    ScaleWidth      =   7200
  21.    Begin VB.PictureBox pnlButtons 
  22.       BorderStyle     =   0  'None
  23.       Height          =   2895
  24.       Left            =   5340
  25.       ScaleHeight     =   2895
  26.       ScaleWidth      =   1875
  27.       TabIndex        =   10
  28.       Top             =   180
  29.       Width           =   1875
  30.       Begin VB.CommandButton cmdCreate 
  31.          Caption         =   "Re-&Create Test Ini"
  32.          Height          =   430
  33.          Left            =   0
  34.          TabIndex        =   16
  35.          Top             =   0
  36.          Width           =   1800
  37.       End
  38.       Begin VB.CommandButton cmdEnumSection 
  39.          Caption         =   "&Enumerate Section...."
  40.          Height          =   430
  41.          Left            =   0
  42.          TabIndex        =   15
  43.          Top             =   480
  44.          Width           =   1800
  45.       End
  46.       Begin VB.CommandButton cmdGetValue 
  47.          Caption         =   "&Get Value for Key..."
  48.          Height          =   430
  49.          Left            =   0
  50.          TabIndex        =   14
  51.          Top             =   960
  52.          Width           =   1800
  53.       End
  54.       Begin VB.CommandButton cmdDeleteKey 
  55.          Caption         =   "&Delete Key..."
  56.          Height          =   430
  57.          Left            =   0
  58.          TabIndex        =   13
  59.          Top             =   1920
  60.          Width           =   1800
  61.       End
  62.       Begin VB.CommandButton cmdDeleteSection 
  63.          Caption         =   "Delete &Section..."
  64.          Height          =   430
  65.          Left            =   0
  66.          TabIndex        =   12
  67.          Top             =   2400
  68.          Width           =   1800
  69.       End
  70.       Begin VB.CommandButton cmdSetValue 
  71.          Caption         =   "Set &Value for Key..."
  72.          Height          =   430
  73.          Left            =   0
  74.          TabIndex        =   11
  75.          Top             =   1440
  76.          Width           =   1800
  77.       End
  78.    End
  79.    Begin VB.ListBox lstIni 
  80.       Height          =   5325
  81.       Left            =   180
  82.       TabIndex        =   9
  83.       Top             =   180
  84.       Width           =   5115
  85.    End
  86.    Begin VB.Frame fraInfo 
  87.       Caption         =   "cIniFile Parameters:"
  88.       Height          =   2535
  89.       Left            =   5340
  90.       TabIndex        =   0
  91.       Top             =   3060
  92.       Width           =   1815
  93.       Begin VB.TextBox txtInfo 
  94.          Height          =   315
  95.          Index           =   3
  96.          Left            =   120
  97.          TabIndex        =   8
  98.          Top             =   2100
  99.          Width           =   1635
  100.       End
  101.       Begin VB.TextBox txtInfo 
  102.          Height          =   315
  103.          Index           =   2
  104.          Left            =   120
  105.          TabIndex        =   7
  106.          Top             =   1500
  107.          Width           =   1635
  108.       End
  109.       Begin VB.TextBox txtInfo 
  110.          Height          =   315
  111.          Index           =   1
  112.          Left            =   120
  113.          TabIndex        =   6
  114.          Top             =   960
  115.          Width           =   1635
  116.       End
  117.       Begin VB.TextBox txtInfo 
  118.          Height          =   315
  119.          Index           =   0
  120.          Left            =   120
  121.          TabIndex        =   5
  122.          Top             =   420
  123.          Width           =   1635
  124.       End
  125.       Begin VB.Label lblInfo 
  126.          Caption         =   "Value:"
  127.          Height          =   195
  128.          Index           =   3
  129.          Left            =   120
  130.          TabIndex        =   4
  131.          Top             =   1860
  132.          Width           =   1995
  133.       End
  134.       Begin VB.Label lblInfo 
  135.          Caption         =   "Key:"
  136.          Height          =   195
  137.          Index           =   2
  138.          Left            =   120
  139.          TabIndex        =   3
  140.          Top             =   1320
  141.          Width           =   1995
  142.       End
  143.       Begin VB.Label lblInfo 
  144.          Caption         =   "Section:"
  145.          Height          =   195
  146.          Index           =   1
  147.          Left            =   120
  148.          TabIndex        =   2
  149.          Top             =   780
  150.          Width           =   1995
  151.       End
  152.       Begin VB.Label lblInfo 
  153.          Caption         =   "Path:"
  154.          Height          =   195
  155.          Index           =   0
  156.          Left            =   60
  157.          TabIndex        =   1
  158.          Top             =   180
  159.          Width           =   1695
  160.       End
  161.    End
  162. Attribute VB_Name = "fTestIni"
  163. Attribute VB_GlobalNameSpace = False
  164. Attribute VB_Creatable = False
  165. Attribute VB_PredeclaredId = True
  166. Attribute VB_Exposed = False
  167. Option Explicit
  168. Private m_cIni As New cInifile
  169. Private Sub ShowIniAndParameters()
  170. Dim sGet As String
  171. Dim sSections() As String
  172. Dim iSectionCount As Long
  173. Dim sKeys() As String
  174. Dim iKeycount As Long
  175. Dim iSection As Long
  176. Dim iKey As Long
  177. Dim lSect As Long
  178.     lstIni.Clear
  179.     With m_cIni
  180.         .EnumerateAllSections sSections(), iSectionCount
  181.         For iSection = 1 To iSectionCount
  182.             lstIni.AddItem "[" & sSections(iSection) & "]"
  183.             lSect = lstIni.NewIndex
  184.             lstIni.ItemData(lSect) = -1
  185.             .Section = sSections(iSection)
  186.             .EnumerateCurrentSection sKeys(), iKeycount
  187.             For iKey = 1 To iKeycount
  188.                 .Key = sKeys(iKey)
  189.                 lstIni.AddItem .Key & "=" & .Value
  190.                 lstIni.ItemData(lstIni.NewIndex) = lSect
  191.             Next iKey
  192.         Next iSection
  193.         If (lstIni.ListCount > 0) Then
  194.             lstIni.ListIndex = lstIni.ListCount - 1
  195.         End If
  196.         txtInfo(0) = .Path
  197.         txtInfo(1) = .Section
  198.         txtInfo(2) = .Key
  199.         txtInfo(3) = .Value
  200.     End With
  201. End Sub
  202. Private Sub CreateTestIni()
  203. Dim i As Long
  204. Dim iNd As Long
  205.     ' Create an Ini File to play with:
  206.     On Error Resume Next
  207.         Kill App.Path & "\TEST.INI"
  208.     On Error GoTo 0
  209.     With m_cIni
  210.         .Path = App.Path & "\TEST.INI"
  211.         .Section = "Window"
  212.         .Key = "Toolbar"
  213.         .Value = "1"
  214.         .Key = "Statusbar"
  215.         .Value = "1"
  216.         .Key = "Maximised"
  217.         .Value = (Me.WindowState = vbMaximized)
  218.         .Key = "Left"
  219.         .Value = Me.Left
  220.         .Key = "Top"
  221.         .Value = Me.Top
  222.         .Key = "Width"
  223.         .Value = Me.Width
  224.         .Key = "Height"
  225.         .Value = Me.Height
  226.         .Key = "Title"
  227.         .Value = App.Title
  228.         .Section = "Options"
  229.         .Key = "ShowTips"
  230.         .Value = "1"
  231.         .Key = "OpenInNewWindow"
  232.         .Value = "0"
  233.         .Section = "Controls"
  234.         For i = 0 To Me.Controls.Count - 1
  235.             .Key = "Control" & i
  236.             Err.Clear
  237.             On Error Resume Next
  238.             iNd = Me.Controls(i).Index
  239.             If (Err.Number = 0) Then
  240.                 .Value = Me.Controls(i).Name & "," & CStr(iNd)
  241.             Else
  242.                 .Value = Me.Controls(i).Name
  243.             End If
  244.         Next i
  245.     End With
  246.     ShowIniAndParameters
  247. End Sub
  248. Private Sub cmdCreate_Click()
  249.     CreateTestIni
  250. End Sub
  251. Private Sub cmdDeleteKey_Click()
  252.     With m_cIni
  253.         .Path = txtInfo(0)
  254.         .Section = txtInfo(1)
  255.         .Key = txtInfo(2)
  256.         .DeleteKey
  257.         If Not (.Success) Then
  258.             MsgBox "Delete Key Failed.", vbInformation
  259.         End If
  260.     End With
  261.     ShowIniAndParameters
  262. End Sub
  263. Private Sub cmdDeleteSection_Click()
  264.     With m_cIni
  265.         .Path = txtInfo(0)
  266.         .Section = txtInfo(1)
  267.         .DeleteSection
  268.         If Not (.Success) Then
  269.             MsgBox "Delete Section Failed.", vbInformation
  270.         End If
  271.     End With
  272.     ShowIniAndParameters
  273. End Sub
  274. Private Sub cmdEnumSection_Click()
  275. Dim sKey() As String, iCount As Long, i As Long
  276. Dim sOut As String
  277.     With m_cIni
  278.         .Path = txtInfo(0)
  279.         .Section = txtInfo(1)
  280.         .EnumerateCurrentSection sKey(), iCount
  281.         If (iCount > 0) Then
  282.             For i = 1 To iCount
  283.                 sOut = sOut & vbCrLf & "    " & sKey(i)
  284.             Next i
  285.             MsgBox "Section contains:" & sOut, vbInformation
  286.         Else
  287.             MsgBox "Section is empty.", vbInformation
  288.         End If
  289.     End With
  290. End Sub
  291. Private Sub cmdGetValue_Click()
  292.     With m_cIni
  293.         .Path = txtInfo(0)
  294.         .Section = txtInfo(1)
  295.         .Key = txtInfo(2)
  296.         .Default = "THIS IS THE DEFAULT"
  297.         txtInfo(3) = .Value
  298.         If Not (.Success) Then
  299.             MsgBox "Failed to get value.", vbInformation
  300.         End If
  301.     End With
  302. End Sub
  303. Private Sub cmdSetValue_Click()
  304.     With m_cIni
  305.         .Path = txtInfo(0)
  306.         .Section = txtInfo(1)
  307.         .Key = txtInfo(2)
  308.         .Value = txtInfo(3)
  309.         If Not (.Success) Then
  310.             MsgBox "Failed to set value.", vbInformation
  311.         End If
  312.     End With
  313.     ShowIniAndParameters
  314. End Sub
  315. Private Sub Form_Load()
  316.     With m_cIni
  317.         .Path = App.Path & "\PTESTINI.INI"
  318.         .Section = Me.Name
  319.         .LoadFormPosition Me, Me.Width, Me.Height
  320.     End With
  321.     CreateTestIni
  322. End Sub
  323. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  324.     With m_cIni
  325.         .Path = App.Path & "\PTESTINI.INI"
  326.         .Section = Me.Name
  327.         .SaveFormPosition Me
  328.     End With
  329. End Sub
  330. Private Sub Form_Resize()
  331. Dim lL As Long
  332.     On Error Resume Next
  333.     lL = Me.ScaleWidth - fraInfo.Width - 2 * Screen.TwipsPerPixelX
  334.     lstIni.Move 2 * Screen.TwipsPerPixelX, 2 * Screen.TwipsPerPixelY, lL - 2 * Screen.TwipsPerPixelY, Me.ScaleHeight - 4 * Screen.TwipsPerPixelY
  335.     pnlButtons.Move lL, lstIni.Top
  336.     fraInfo.Move lL
  337. End Sub
  338. Private Sub lstIni_Click()
  339. Dim sItem As String
  340. Dim iPos As Long
  341.     If (lstIni.ListIndex > -1) Then
  342.         If (lstIni.ItemData(lstIni.ListIndex) = -1) Then
  343.             sItem = lstIni.List(lstIni.ListIndex)
  344.             ' Key:
  345.             txtInfo(1) = Mid$(sItem, 2, Len(sItem) - 2)
  346.             txtInfo(2) = ""
  347.             cmdGetValue.Enabled = False
  348.             cmdSetValue.Enabled = False
  349.             cmdDeleteKey.Enabled = False
  350.         Else
  351.             sItem = lstIni.List(lstIni.ItemData(lstIni.ListIndex))
  352.             txtInfo(1) = Mid$(sItem, 2, Len(sItem) - 2)
  353.             sItem = lstIni.List(lstIni.ListIndex)
  354.             iPos = InStr(sItem, "=")
  355.             txtInfo(2) = Left$(sItem, (iPos - 1))
  356.             txtInfo(3) = Mid$(sItem, (iPos + 1))
  357.             cmdGetValue.Enabled = True
  358.             cmdSetValue.Enabled = True
  359.             cmdDeleteKey.Enabled = True
  360.         End If
  361.     End If
  362. End Sub
  363.